#include "aw_windows.h"
#include "../menu.h"
#include "avi_define.h"
#include "vob_define.h"
#include "rm_define.h"
#include "gplayer_app.h"
#include "ctrlconvert.h"
#include "aw_sys_app.h"
#include "aw_init_display.h"
#include "logo_dat.h"
#include "LogoEvent.h"
#include "MoviePlayBackEvent.h"
#include "aw_gui_app.h"
#include "NetmenuSetupEvent.h"
#include "user.h"
#include "resource/string_dat.h"

#include <aw_playlist2.h>
#include "../aw_AVI_app.h"

/*
	in this part, 'num' is self-define for :
	1x Nomal play or Pause
	2x FF or FB play
	3x Zoom play
	4x Next play
	5x Prev play	
	
	this 'num' used in fun : 
							DisPlayMoviePlayState() ;
							GetNowVideoStatus();
							gPlayerPlayState();
*/

#define   	ORIGINAL		0x99
#define		PREV			0x1
#define		FASTBACK		0x2
#define 	PLAY			0x3
#define 	PAUSE 			0x4
#define 	FASTFOR			0x5
#define		NEXT			0x6
#define		STOP			0x7
#define		ZOOM			0x8
#define		ZOOMx2			0x9
#define		ZOOMx3			0xA
#define		ZOOMx4			0xB
#define		FFx2			0x10
#define		FFx3			0x11
#define		FFx4			0x12
#define		FBx2			0x13
#define		FBx3			0x14
#define		FBx4			0x15
#define 	OTHER			0x16
#define		SUBTITLE		0x17


//PIXELVAL oldcolor;
//#define GRAY_COLOR 2

static int CurrInfoBarIndex = 3 ;
static int WaittingTime = 0 ;
static int WaitFor = 7 ;
static int audio_track_flag = 0;

INT8U PlayEffect = PLAY ;
INT8U PlayState = ZOOM ;   // real state
INT8U VideoState = PAUSE;  // virtual State
INT8U ZoomEffect = ZOOM ;
INT8U FFBEffect = ZOOM ;
INT8U PlayBack_unMute_WaitFor = 3 ;
INT8U PlayBack_unMute_waitting = 0 ;
INT8U PlayBack_unMute_ShowFlag = 0 ;
INT8U PlayBackResume = 0 ;
INT8U PlayBackHome = 0 ;
static INT32S time_hour = 0 ;
static INT32S time_min = 0 ;
static INT32S time_sec = 0 ;
#ifdef TIME_SEARCH
INT32S search_time_hour = 0 ;
INT32S search_time_min = 0 ;
INT32S search_time_sec = 0 ;
extern VIDEO_INFO video_inf;
extern INT8U TimeSearchFlag;
static enum time_search_type  cur_time_search= time_search_none;
INT8U UpdateTime = 0;
#endif

#ifdef RESUME_PLAY
extern RESUME_FILEINFO resume_file;
extern INT8U ResumeFunction;
#endif

static INT8U subpic_enable = 0 ;

extern INT8U isMute ;
extern INT32U NODIR_FLAG ;
extern unsigned char Volume_Value ;
extern AVI_SUB_t subpic_status;


const unsigned char *vol_value[] = 
{
    	ICON_2_0_480,
    	ICON_2_1_480,
    	ICON_2_2_480,
    	ICON_2_3_480,
    	ICON_2_4_480,
    	ICON_2_5_480,
    	ICON_2_6_480,
    	ICON_2_7_480
} ;
void UpdateBarIconSelectState(int OldFocus, int NewFocus);
void IniPlayBackVariable()
{
	PlayEffect = PLAY ;
	PlayState = ZOOM ;   
	ZoomEffect = ZOOM ;
	FFBEffect = ZOOM ;

}

int GetNowVideoStatus()
{
	int num = 11 ;
	switch(PlayState){
		case PLAY:
			num = 11 ;
			break;	
			
		case PAUSE:
			num = 12 ;
			break;

		case FFx2:
			num = 22 ;
			break;
			
		case FFx3:
			num = 23 ;
			break;
			
		case FFx4:
			num = 24 ;
			break;
			
		case FBx2:
			num = 25 ;
			break;
			
		case FBx3:
			num = 26 ;
			break;
			
		case FBx4:
			num = 27 ;
			break;															

		case ZOOM:
			num = 34 ;
			break;
			
		case ZOOMx2:
			num = 31 ;
			break;
			
		case ZOOMx3:
			num = 32 ;
			break;
			
		case ZOOMx4:
			num = 33 ;
			break;
		
		default:
			break;	
	}
	return num ;
}


INT32U OnEnterExpress(void)
{
	PHWND hwnd = AWFindWinCtrlByName(MoviePlayInfoBar);
	PHWND dir_hwnd = AWFindWinCtrlByName(MoviePlayState);
	PHWND paint_hwnd = AWFindWinCtrlByName(AviSubCtrl);
	if(!hwnd)
		return UOP_NOP;
	#ifdef TIME_SEARCH
	if(cur_time_search != time_search_none)
	{
		CurrInfoBarIndex = 3;
		cur_time_search= time_search_none;
		UpdateBarIconSelectState(9, CurrInfoBarIndex);
		return UOP_TIME_PLAY;
	}
	#endif
	if(VideoState){
		switch(VideoState){
			case PREV:
				return UOP_PREVIOUS_CHAP;
				
			case FASTBACK:
				if(PlayEffect == PLAY)
					hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
				else 
				if(PlayEffect == FBx4)
					hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
					
				if(AWIsVisibleWinControl(hwnd))
				{
					hwnd->pClass->ClassProc(hwnd,WM_PAINT_DRAW_INFO,3);
					hwnd->pClass->ClassProc(hwnd,WM_PAINT_FINISH,0);	
				}
								
				return UOP_FAST_BACKWARD;
				
			case PLAY:
				hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_FOCUS_PLBK ;
					
				if(AWIsVisibleWinControl(hwnd)) 
				{
					hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 3) ;
					hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 1) ;
				}
				VideoState = PAUSE ;
				return UOP_END_PAUSE;
				
			case PAUSE:
				hwnd->draw_info[3].draw_data = (INT32U)ICON_PAUSE_FOCUS_PLBK ;
									
				if(AWIsVisibleWinControl(hwnd)) 
				{
					hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 3) ;
					hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 1) ;
				}				
				VideoState = PLAY ;
				return UOP_PAUSE;
				
			case FASTFOR:
				if(PlayEffect == PLAY)
					hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
				else 
				if(PlayEffect == FFx4)
					hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
					
				if(AWIsVisibleWinControl(hwnd))
				{
					hwnd->pClass->ClassProc(hwnd,WM_PAINT_DRAW_INFO,3);
					hwnd->pClass->ClassProc(hwnd,WM_PAINT_FINISH,0);	
				}				
				return UOP_FAST_FORWARD;
				
			case NEXT:
				return UOP_NEXT_CHAP;
				
			case STOP:
				PlayBackResume = 1 ;
				return UOP_STOP;
				
			case ZOOM:
				return UOP_ZOOM;

			case SUBTITLE:
				if(subpic_status == NO_SUBPIC)
					return;
				
				if(subpic_enable) 
				{
					AviSetSubOn(0) ;
					subpic_enable = 0 ;
					if(paint_hwnd)
					{
						AWSendMessage(paint_hwnd, WM_PAINT_DRAW_INFO, 0) ;
						AWSendMessage(paint_hwnd,WM_PAINT_FINISH,0);
						AWHideWinControl(paint_hwnd);
					}
					dir_hwnd->draw_info[0].draw_data = (INT32U)ICON_SUB_NO_PLBK ;
					dir_hwnd->draw_info[1].draw_data = (INT32U)0 ;
					dir_hwnd->draw_info[2].draw_data = (INT32U)0 ;
//					dir_hwnd->draw_info[3].draw_data = (INT32U)0 ;
				}
				else 
				{
					AviSetSubOn(1) ;
					subpic_enable = 1 ;
					if(paint_hwnd)
					AWShowWinControl(paint_hwnd,0);
					dir_hwnd->draw_info[0].draw_data = (INT32U)ICON_SUB_LOSE_PLBK ;
					dir_hwnd->draw_info[1].draw_data = (INT32U)0 ;
					dir_hwnd->draw_info[2].draw_data = (INT32U)0 ;
//					dir_hwnd->draw_info[3].draw_data = (INT32U)0 ;
				}
			dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 0);
			dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 1);
			dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 2);
//			dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 3);
			dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_FINISH, 0);
			PlayBack_unMute_ShowFlag = 1 ;	
			PlayBack_unMute_waitting = 0 ;


			default:
				return UOP_NOP;
		} // end Switch		
	}// end if
}

void UpdateBarIconSelectState(int OldFocus, int NewFocus)
{
	PHWND dir_hwnd = AWFindWinCtrlByName(MoviePlayInfoBar);
	
	if(dir_hwnd){
		switch(OldFocus){
			case 1:
				dir_hwnd->draw_info[OldFocus].draw_data = (INT32U)ICON_PREV_LOSE_PLBK ;
				break;
				
			case 2:
				dir_hwnd->draw_info[OldFocus].draw_data = (INT32U)ICON_INFOBAR_FB_LOSE_PLBK ;
				break;
				
			case 3:
				if(PlayEffect == PLAY)
					dir_hwnd->draw_info[OldFocus].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
				else
					dir_hwnd->draw_info[OldFocus].draw_data = (INT32U)ICON_PAUSE_LOSE_PLBK ;
					
				break;
				
			case 4:
				dir_hwnd->draw_info[OldFocus].draw_data = (INT32U)ICON_INFOBAR_FF_LOSE_PLBK ;
				break;
				
			case 5:
				dir_hwnd->draw_info[OldFocus].draw_data = (INT32U)ICON_NEXT_LOSE_PLBK ;
				break;
				
			case 6:
				dir_hwnd->draw_info[OldFocus].draw_data = (INT32U)ICON_STOP_LOSE_PLBK ;
				break;
				
			case 7:
				dir_hwnd->draw_info[OldFocus].draw_data = (INT32U)ICON_ZOOM_LOSE_PLBK ;
				break;				

			case 8:
				dir_hwnd->draw_info[OldFocus].draw_data = (INT32U)ICON_SUB_LOSE_PLBK ;
				break;	
			#ifdef TIME_SEARCH
			case 9:
				if(NewFocus == 8)
				{
					cur_time_search= time_search_none;
				}
				break;
			#endif	
			default:
				break;				
		}
		
		switch(NewFocus){
			case 1:					
				dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_PREV_FOCUS_PLBK ;
				VideoState = PREV ;
				CurrInfoBarIndex = 1 ;
				break;
				
			case 2:
				dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_INFOBAR_FB_FOCUS_PLBK ;
				VideoState = FASTBACK ;
				CurrInfoBarIndex = 2 ;
				break;
				
			case 3:
				if(PlayEffect == PLAY){
					dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_PLAY_FOCUS_PLBK ;
					VideoState = PAUSE ;
				}
				else {
				//if(PlayEffect == PAUSE){
					dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_PAUSE_FOCUS_PLBK ;
					VideoState = PLAY ;
				}
//				else { 
//					dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_PLAY_FOCUS_PLBK ;
//					VideoState = PLAY ;					
//				}	
				CurrInfoBarIndex = 3 ;
				break;
				
			case 4:
				dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_INFOBAR_FF_FOCUS_PLBK ;
				VideoState = FASTFOR ;
				CurrInfoBarIndex = 4 ;
				break;
				
			case 5:
				dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_NEXT_FOCUS_PLBK ;	
				VideoState = NEXT ;
				CurrInfoBarIndex = 5 ;
				break;
				
			case 6:
				dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_STOP_FOCUS_PLBK ;					
				VideoState = STOP ;
				CurrInfoBarIndex = 6 ;
				break;
				
			case 7:
				dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_ZOOM_FOCUS_PLBK ;
				VideoState = ZOOM ;
				CurrInfoBarIndex = 7 ;
				break;		

			case 8:
				dir_hwnd->draw_info[NewFocus].draw_data = (INT32U)ICON_SUB_FOCUS_PLBK ;
				VideoState = SUBTITLE ;
				CurrInfoBarIndex = 8 ;
				break;
			#ifdef TIME_SEARCH
			case 9:
				cur_time_search= time_search_hour;
				break;

			case 10:
				cur_time_search= time_search_min;
				break;

			case 11:
				cur_time_search= time_search_sec;
				break;
			#endif	

		}	
	}
	
	if(AWIsVisibleWinControl(dir_hwnd)&&(OldFocus<10)&&(NewFocus<10))
	{	
		AWPostMessage(dir_hwnd,WM_PAINT_DRAW_INFO,OldFocus);
		AWPostMessage(dir_hwnd,WM_PAINT_DRAW_INFO,NewFocus);
		AWPostMessage(dir_hwnd,WM_PAINT_FINISH,0);
	}
}



INT32S WinMoviePlayBackOnShow(PHWND hwnd, INT32S lpParam)
{
	osdsettpval(2,0xf);
	
	IniPlayBackVariable();
	
	WaittingTime = 0 ;
	PlayBack_unMute_ShowFlag = 0 ;
	CurrInfoBarIndex = 3 ;	
	VideoState = PAUSE; 
	PlayBackResume = 0 ;
	PlayBackHome = 0 ;

//	subpic_enable = 0 ;
	
	PHWND dir_hwnd = AWFindWinCtrlByName(MoviePlayInfoBar);
	if(dir_hwnd)
	{
          dir_hwnd->draw_info[1].draw_data = (INT32U)ICON_PREV_LOSE_PLBK ;
          dir_hwnd->draw_info[2].draw_data = (INT32U)ICON_INFOBAR_FB_LOSE_PLBK ;
          dir_hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_FOCUS_PLBK ;
          dir_hwnd->draw_info[4].draw_data = (INT32U)ICON_INFOBAR_FF_LOSE_PLBK ;
          dir_hwnd->draw_info[5].draw_data = (INT32U)ICON_NEXT_LOSE_PLBK ;
          dir_hwnd->draw_info[6].draw_data = (INT32U)ICON_STOP_LOSE_PLBK ;
          dir_hwnd->draw_info[7].draw_data = (INT32U)ICON_ZOOM_LOSE_PLBK ;
          dir_hwnd->draw_info[8].draw_data = (INT32U)ICON_SUB_LOSE_PLBK ;	  
	}

    return 0 ;

}


INT32S MoviePlayInfoBarOnKeyPress(PHWND hwnd, INT32S lpParam)
{
	INT32U *key_value = (INT32U *)lpParam ;	
// not do keyevent here
	switch(*key_value){
		case UOP_VOL_MINUS:
		case UOP_VOL_PLUS:
		case UOP_MUTE:
			return 0;
		
		default:
			break;
	}
	
	KeyDownWhenInfoBarOnshowOrOnHide(hwnd, lpParam);
				
    return 0 ;
}

void gPlayerUpdateVideofPlayTime(INT32S curr_time)
{
	static INT32S prev_time = -1;
    if(prev_time == curr_time)
        return;
    else
        prev_time = curr_time;
		time_hour = curr_time/3600 ;
		time_min = (curr_time%3600)/60 ;
		time_sec = (curr_time%3600)%60 ;

	#ifdef RESUME_PLAY
	    static INT32S resume_time = 0;
        if(ResumeFunction == 1)
        {
            if(curr_time == 0)
                resume_time = 0;
            resume_file.time = (time_hour<<16)|(time_min<<8)|time_sec;
    	#if RESUME_INTERVAL_TIME
            if((curr_time - resume_time > RESUME_INTERVAL_TIME)||(resume_time - curr_time>RESUME_INTERVAL_TIME))
            {
                resume_time = curr_time;
                //resume_file.time = (time_hour<<16)|(time_min<<8)|time_sec;
                SetResumeTimePara(resume_file.time);
    		}
        #endif
        }
	#endif

	#ifdef TIME_SEARCH
	if (cur_time_search == time_search_none)
	{

		search_time_hour = time_hour;
		search_time_min = time_min;
		search_time_sec = time_sec;
    #endif
		sprintf(infobar_time_str, "%02d:%02d:%02d", time_hour, time_min, time_sec);
		
		PHWND hwnd = AWFindWinCtrlByName(MoviePlayInfoBar);
		if(hwnd&&AWIsVisibleWinControl(hwnd))
		{
		        hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 9);
		        hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 10);
		        hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
		}
	#ifdef TIME_SEARCH
	}
	#endif
		
}
#ifdef TIME_SEARCH
void gPlayerUpdateSearchTime(INT8U add_time)
{
	INT32S total_time_hour = video_inf.total_time/3600;
	INT32S total_time_min = (video_inf.total_time%3600)/60;
	INT32S total_time_sec = video_inf.total_time%60;
	
	if(add_time)
	{
		switch(cur_time_search)
		{
			case time_search_hour:
				if((search_time_hour<total_time_hour-1)||(search_time_hour==total_time_hour-1&&search_time_min<=total_time_min))
					search_time_hour++;
				if(search_time_hour >99)
					search_time_hour = 0;
			break;
			case  time_search_min:
				if(search_time_hour<total_time_hour)
					search_time_min++;
				else if(search_time_hour==total_time_hour&&search_time_min<total_time_min-1)
					search_time_min++;
				else if(search_time_sec<total_time_sec&&search_time_min<total_time_min)
					search_time_min++;
				if(search_time_min == 60)
					search_time_min = 0;
			break;
			case time_search_sec:
				if(search_time_hour<total_time_hour)
					search_time_sec++;
				else if(search_time_min<total_time_min)
					search_time_sec++;
				else if (search_time_min==total_time_min&&search_time_sec<total_time_sec)
					search_time_sec++;
				if(search_time_sec ==60)
					search_time_sec = 0;
			break;	
			default:
			break;
		}
	}else
	{
		switch(cur_time_search)
		{
			case time_search_hour:
				if(search_time_hour>0)
					search_time_hour--;
			break;
			case  time_search_min:
				if(search_time_min>0)
					search_time_min--;
				else if(search_time_min==0 &&search_time_hour <total_time_hour)
					search_time_min = 59;
			break;
			case time_search_sec:
				if(search_time_sec>0)
					search_time_sec--;
				else if(search_time_sec==0 &&(search_time_hour <total_time_hour||search_time_min <total_time_min))
					search_time_sec = 59;
			break;	
			default:
			break;
		}

	}
}
#endif

#ifdef TIME_SEARCH
void gPlayerUpdateTimeInfo(void)
{

	sprintf(infobar_time_str, "%02d:%02d:%02d", search_time_hour,search_time_min,search_time_sec);
	PHWND hwnd = AWFindWinCtrlByName(MoviePlayInfoBar);
	if(hwnd&&AWIsVisibleWinControl(hwnd))
	{
	        hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 9);
	        hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 10);
	        hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
	}	
}
#endif
void gPlayerPlayState(int flag, int msg_id, int msg_value, INT8U ff_level, INT8U fb_level)
{
	int num = 0;
	/*
	1* Nomal play or Pause
	2* FF or FB play
	3* Zoom play
	4* Next play
	5* Prev play
	*/
	
	if(flag == 1){  // AVI
		switch(msg_id){
			case NM_AVI_STATUS:
				if((msg_value == 1)||(msg_value == 3))
					num = 11; // play
				else
				if((msg_value == 2)||(msg_value == 4))
					num = 12; // pause
				break;
				
			case NM_AVI_FFFB_SPEED:
				if(msg_value == 2)
					num = 22;
				else
				if(msg_value == 3)		
					num = 23;
				else
				if(msg_value == 4)
					num = 24;
				else
				if(msg_value == 0x8002)
					num = 25;
				else
				if(msg_value == 0x8003)
					num = 26;
				else
				if(msg_value == 0x8004)
					num = 27;
					
				break;
				
			case NM_AVI_VIDEO_ZOOMLEVEL:
				if(msg_value == 1)
					num = 31 ;
				else	
				if(msg_value == 2)
					num = 32 ;
				else
				if(msg_value == 3)
					num = 33 ;
				else
					num = 34 ;
						
				break;

			case NM_AVI_GET_NEXT:
				break;
				
			case NM_AVI_GET_PREV:
				break;
						
			case NM_AVI_END_OF_PLAY:
				IniPlayBackVariable();
				break;
				
			default:
				break;					
		}
	}
	else
	if(flag == 2){ // VOB
		switch(msg_id){
			case NM_VOB_STATUS:
				if((msg_value == 1)||(msg_value == 3))
					num = 11; // play
				else
				if((msg_value == 2)||(msg_value == 4))
					num = 12; // pause
				else
				if(msg_value == VOB_NON_SEAMLESS_FF){
					if(ff_level == 2)
						num = 22;
					else
					if(ff_level == 3)		
						num = 23;
					else
					if(ff_level == 4)
						num = 24;
					else
					if(fb_level == 2)
						num = 25;
					else
					if(fb_level == 3)
						num = 26;
					else
					if(fb_level == 4)
						num = 27;
				}
				break;

			case NM_VOB_VIDEO_ZOOMLEVEL:
				if(msg_value == 1)
					num = 31 ;
				else	
				if(msg_value == 2)
					num = 32 ;
				else
				if(msg_value == 3)
					num = 33 ;
				else
					num = 34 ;
						
				break;

			case NM_VOB_GET_NEXT:
				break;
				
			case NM_VOB_GET_PREV:
				break;
						
			case NM_VOB_END_OF_PLAY:
				IniPlayBackVariable();
				break;
				
			default:
				break;	
		}
	}
	else if(flag == 3){ // RM
		switch(msg_id){
			case NM_RM_STATUS:
				if(msg_value == 3)
					num = 11; // play
				else
				if(msg_value == 4) 
					num = 12; // pause
				break;
				
			case NM_RM_FFFB_SPEED:
				if(msg_value == 2)
					num = 22;
				else
				if(msg_value == 3)		
					num = 23;
				else
				if(msg_value == 4)
					num = 24;
				else
				if(msg_value == 0x8002)
					num = 25;
				else
				if(msg_value == 0x8003)
					num = 26;
				else
				if(msg_value == 0x8004)
					num = 27;
					
				break;
				
			case NM_RM_VIDEO_ZOOMLEVEL:
				if(msg_value == 1)
					num = 31 ;
				else	
				if(msg_value == 2)
					num = 32 ;
				else
				if(msg_value == 3)
					num = 33 ;
				else
					num = 34 ;  // when zoom out 
						
				break;

			case NM_AVI_GET_NEXT:
				break;
				
			case NM_AVI_GET_PREV:
				break;
				
			case NM_RM_END_OF_PLAY:
				IniPlayBackVariable();
				break;
				
			default:
				break;	
		}		
	}
	else if(flag == 4){ // MOV
		switch(msg_value){
			case GPLAYER_PLAY:
					num = 11; 
				break;
				
			case GPLAYER_PAUSE:
					num = 12; 
				break;
				
			case GPLAYER_SEAMLESS_FF:
				if(ff_level == 2)
					num = 22;
				else
				if(ff_level == 3)		
					num = 23;
				else
				if(ff_level == 4)
					num = 24;
				break;
					
			case GPLAYER_SEAMLESS_FB:
				if(fb_level == 2)
					num = 25;
				else
				if(fb_level == 3)
					num = 26;
				else
				if(fb_level == 4)
					num = 27;
					
				break;
				
			case NM_END_OF_PLAY:
				IniPlayBackVariable();
				break;
	
//			case NM_RM_VIDEO_ZOOMLEVEL:
//				break;

			default:
				break;	
		}		
	}	
	
//--------------------------------------------------------------------------
// special Action 
	if(isMute == MUTE)
	{
		upgradePlayState(&num);
		return ;
	}
	

	if(num == 11)
	{
		RefurbishInfoBar(num);
		PlayEffect = PLAY ;
		if(ZoomEffect == ZOOMx2)
			num = 31 ;
		else if(ZoomEffect == ZOOMx3)	
			num = 32 ;
		else if(ZoomEffect == ZOOMx4)	
			num = 33 ;
	}
	

//--------------------------------------------------------------------------
	upgradePlayState(&num);
	DisPlayMoviePlayState(num);
	return ;
}	

void upgradePlayState(int *num)
{
	switch(*num){
		case 11:
			PlayState = PLAY ;
			PlayEffect = PLAY ;
			break;
			
		case 12:
			if(PlayState == PAUSE)
				*num = ORIGINAL ;
			else
				PlayState = PAUSE ;
				
			PlayEffect = PAUSE ;
			break;
			
		case 22:
			if(PlayState == FFx2)
				*num = ORIGINAL ;
			else
				PlayState = FFx2 ;
				
			PlayEffect = FFx2 ;
			break;
			
		case 23:
			if(PlayState == FFx3)
				*num = ORIGINAL ;
			else
				PlayState = FFx3 ;
				
			PlayEffect = FFx3 ;
			break;
			
		case 24:
			if(PlayState == FFx4)
				*num = ORIGINAL ;
			else
				PlayState = FFx4 ;
			
			PlayEffect = FFx4 ;
			break;
			
		case 25:
			if(PlayState == FBx2)
				*num = ORIGINAL ;
			else
				PlayState = FBx2 ;
				
			PlayEffect = FBx2 ;
			break;
			
		case 26:
			if(PlayState == FBx3)
				*num = ORIGINAL ;
			else
				PlayState = FBx3 ;
				
			PlayEffect = FBx3 ;
			break;
			
		case 27:
			if(PlayState == FBx4)
				*num = ORIGINAL ;
			else
				PlayState = FBx4 ;
				
			PlayEffect = FBx4 ;
			break;
			
		case 31:
			if(PlayState == ZOOMx2)
				*num = ORIGINAL ;
			else
				PlayState = ZOOMx2;
				
			ZoomEffect = ZOOMx2;
			break;
			
		case 32:
			if(PlayState == ZOOMx3)
				*num = ORIGINAL ;
			else
				PlayState = ZOOMx3;
				
			ZoomEffect = ZOOMx3;
			break;
			
		case 33:
			if(PlayState == ZOOMx4)
				*num = ORIGINAL ;
			else
				PlayState = ZOOMx4;
				
			ZoomEffect = ZOOMx4;
			break;
			
		case 34: // zoom out
			if(PlayState == ZOOM)
				*num = ORIGINAL ;
			else
				PlayState = ZOOM;
				
			ZoomEffect = ZOOM;
						
			if(PlayEffect == FFx2){
				*num = 22 ;
			}
			else
			if(PlayEffect == FFx3){
				*num = 23 ;
			}	
			else
			if(PlayEffect == FFx4){
				*num = 24 ;
			}	
			else
			if(PlayEffect == FBx2){
				*num = 25 ;
			}	
			else
			if(PlayEffect == FBx3){
				*num = 26 ;
			}	
			else
			if(PlayEffect == FBx4){
				*num = 27 ;
			}

			break;			
			
		default:
		 	break;										
	}	
	return;
}

void DisPlayMoviePlayState(int num)
{
	PHWND hwnd = AWFindWinCtrlByName(MoviePlayState);
	if(hwnd){
		switch(num){
			case 11: // play
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS120X32 ;
				hwnd->draw_info[1].draw_data = (INT32U)0 ;
				hwnd->draw_info[2].draw_data = (INT32U)0 ;
				hwnd->draw_info[3].draw_data = (INT32U)0 ;	
				//PlayState = PLAY ;
				break ;
				
			case 12: // pause
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_PAUSE_FOCUS_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)0 ;
				hwnd->draw_info[3].draw_data = (INT32U)0 ;
				// PlayState = PAUSE ;
				break ;	
				
			case 22: // FF*2
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_INFOBAR_FF_LOSE_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)ICON_ZOOMLEVEL_PLBK ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_ZOOMLEVEL_2_PLBK ;	
				// PlayState = FFx2 ;
				break ;	
				
			case 23: // FF*3
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_INFOBAR_FF_LOSE_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)ICON_ZOOMLEVEL_PLBK ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_ZOOMLEVEL_3_PLBK ;	
				// PlayState = FFx3 ;
				break ;	
				
			case 24: // FF*4
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_INFOBAR_FF_LOSE_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)ICON_ZOOMLEVEL_PLBK ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_ZOOMLEVEL_4_PLBK ;	
				// PlayState = FFx4 ;
				break ;	
				
			case 25: // FB*2
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_INFOBAR_FB_LOSE_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)ICON_ZOOMLEVEL_PLBK ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_ZOOMLEVEL_2_PLBK ;
				// PlayState = FBx2 ;
				break ;	
				
			case 26: // FB*3
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_INFOBAR_FB_LOSE_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)ICON_ZOOMLEVEL_PLBK ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_ZOOMLEVEL_3_PLBK ;				
				// PlayState = FBx3 ;
				break ;					
				
			case 27: // FB*4
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_INFOBAR_FB_LOSE_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)ICON_ZOOMLEVEL_PLBK ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_ZOOMLEVEL_4_PLBK ;
				// PlayState = FBx4 ;
				break ;	
				
			case 31: // zoom*2
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_ZOOM_LOSE_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)ICON_ZOOMLEVEL_PLBK ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_ZOOMLEVEL_2_PLBK ;
				// PlayState = ZOOMx2;
				break ;	
				
			case 32: // zoom*3
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_ZOOM_LOSE_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)ICON_ZOOMLEVEL_PLBK ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_ZOOMLEVEL_3_PLBK ;
				// PlayState = ZOOMx3;
				break ;	
				
			case 33: // zoom*4
				hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				hwnd->draw_info[1].draw_data = (INT32U)ICON_ZOOM_LOSE_PLBK ;
				hwnd->draw_info[2].draw_data = (INT32U)ICON_ZOOMLEVEL_PLBK ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_ZOOMLEVEL_4_PLBK ;
				// PlayState = ZOOMx4;
				break ;	
				
			case 34: // zoom*0
				
				if((PlayEffect == PLAY)||(PlayEffect == OTHER))
				{
					hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS120X32 ;
					hwnd->draw_info[1].draw_data = (INT32U)0 ;
				}	
				else
				if(PlayEffect == PAUSE)
				{
					hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
					hwnd->draw_info[1].draw_data = (INT32U)ICON_PAUSE_FOCUS_PLBK ;
				}	
				else
				{
					hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
					hwnd->draw_info[1].draw_data = (INT32U)ICON_ZOOM_LOSE_PLBK ;
					
				}
				// PlayState = ZOOM;
				hwnd->draw_info[2].draw_data = (INT32U)0;
				hwnd->draw_info[3].draw_data = (INT32U)0;
				break ;					
				
			case 41:
				break ;	
				
			case 51:
				break ;	
				
			case 99:
				break;
				
			default:
				return ;
		}
		
		hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 0);
		hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 1);
		hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 2);
		hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 3);
		hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0);
	}
}
#ifdef ZOOM_IN
int MovieResetZoomLevel(void)
{
	if(ZoomEffect != ZOOM){
		PlayState = ZOOM;
		ZoomEffect = ZOOM;
		DisPlayMoviePlayState(34);
		return 1;
	}else
	  return 0;
	
}
#endif
INT32S WinMoviePlayBackHide(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
	PHWND paint_hwnd = AWFindWinCtrlByName(AviSubCtrl);
	
	if(AWIsVisibleWinControl(hwnd))
	{
		switch(msg_type){
			case WM_SECOND_TIMEOUT:
				if(WaittingTime<WaitFor){
					WaittingTime++;
					#ifdef TIME_SEARCH
					if((cur_time_search != time_search_none)&&(UpdateTime == 0))
					{
						if(WaittingTime %2 ==0)
						{
							switch(cur_time_search)
							{
								case time_search_hour:
									sprintf(infobar_time_str, "__:%02d:%02d", search_time_min,search_time_sec);
									break;
								case time_search_min:
									sprintf(infobar_time_str, "%02d:__:%02d", search_time_hour,search_time_sec);
									break;
								case time_search_sec:
									sprintf(infobar_time_str, "%02d:%02d:__",search_time_hour,search_time_min);
									break;
								default: 
									break;
							}
						}else
						{
							sprintf(infobar_time_str, "%02d:%02d:%02d", search_time_hour,search_time_min, search_time_sec);
						}
						PHWND hwnd = AWFindWinCtrlByName(MoviePlayInfoBar);
						if(hwnd&&AWIsVisibleWinControl(hwnd))
						{
						        hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 9);
						        hwnd->pClass->ClassProc(hwnd, WM_PAINT_DRAW_INFO, 10);
						        hwnd->pClass->ClassProc(hwnd, WM_PAINT_FINISH, 0) ;
						}
					}
					#endif
				}
				else
				{
					
					if(subpic_enable)
					{
						AWHideWinControl(hwnd);
//						if(paint_hwnd)
//							AWShowWinControl(paint_hwnd,0);
					}
					else
					{
						AWHideWinControl(hwnd);
					}
					
				}
				break;
				
			default:
				break;
		}
	}
	return 0 ;
}

INT32S MoviePlayStateOnKeyPress(PHWND hwnd, INT32S lpParam) 
{

	return 0 ;
}

INT32S WinMoviePlayBackOnKeyPress(PHWND hwnd, INT32S lpParam)
{
	INT32U *key_value = (INT32U *)lpParam ;	
	PHWND dir_hwnd = AWFindWinCtrlByName(MoviePlayInfoBar);

	switch(*key_value){
		case UOP_ANGLE:
			return 0;
		case UOP_HOME:
		case UOP_LEFT:
		case UOP_RIGHT:
		case UOP_PREVIOUS_CHAP:
		case UOP_FAST_BACKWARD:
		case UOP_END_PAUSE:
		case UOP_FAST_FORWARD:
		case UOP_NEXT_CHAP:
		case UOP_STOP:
		case UOP_ZOOM:
		case UOP_ENTER:
			if(AWIsVisibleWinControl(dir_hwnd)){
				return 0 ;
			}
			else{
				if(*key_value == UOP_ENTER){
					#ifdef KOREAR_REMOTE
					*key_value = UOP_END_PAUSE ;
					#else
					*key_value = UOP_OSD ;
					#endif
					break;
				}	
			}
					
		default:
			break;
	}
	
	KeyDownWhenInfoBarOnshowOrOnHide(dir_hwnd, lpParam);
	return 0 ;
}

void ShowWinMoviePlayBack()
{
	GUIShowWindow(WinMoviePlayBack) ;
	
	ZoomEffect = ZOOM ;
	FFBEffect = ZOOM ;	
	PlayState = ZOOM ;
	PlayEffect = PLAY ;
	
	PHWND dir_hwnd = AWFindWinCtrlByName(MoviePlayState);
	if(dir_hwnd)
	{
		if(isMute == MUTE)
		{
			dir_hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
			dir_hwnd->draw_info[1].draw_data = (INT32U)ICON_MUTE ;
			dir_hwnd->draw_info[2].draw_data = (INT32U)0 ;
			dir_hwnd->draw_info[3].draw_data = (INT32U)0 ;
		}
		else 
		{
			dir_hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS120X32 ;
			dir_hwnd->draw_info[1].draw_data = (INT32U)0 ;
			dir_hwnd->draw_info[2].draw_data = (INT32U)0 ;
			dir_hwnd->draw_info[3].draw_data = (INT32U)0 ;
		}
		dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 0);
		dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 1);
		dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 2);
		dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 3);
		dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_FINISH,1);
	}
	
	dir_hwnd = AWFindWinCtrlByName(MoviePlayInfoBar);
	if(dir_hwnd)
	{
		if(dir_hwnd->draw_info[3].draw_data == (INT32U)ICON_PLAY_LOSE_PLBK)
			dir_hwnd->draw_info[3].draw_data = (INT32U)ICON_PAUSE_LOSE_PLBK ;
		else
		if(dir_hwnd->draw_info[3].draw_data == (INT32U)ICON_PLAY_FOCUS_PLBK)
			dir_hwnd->draw_info[3].draw_data = (INT32U)ICON_PAUSE_FOCUS_PLBK ;
						
		AWHideWinControl(dir_hwnd);
	}
	
}

INT32S MoviePlayInfoBarOnShow(PHWND hwnd, INT32S lpParam)
{
	PlayBack_unMute_WaitFor = 3 ;
	PlayBack_unMute_waitting = 0 ;	

	return 0;	
}


void HideWinMoviePlayBackControl()
{	
	int num = GetNowVideoStatus();
	//upgradePlayState(&num);
	DisPlayMoviePlayState(num);
	
	return;
}

void ChangeSoundTrack(int flag)
{
	int fd;
	audio_output_swap_e config;
		fd = open("/dev/audio_output", O_RDONLY);
	switch(flag){
		case 0:
			config = CHANNEL_SWAP_LR;
			break;
		case 1:
			config = CHANNEL_SWAP_LL;
			break;
		case 2:
			config = CHANNEL_SWAP_RR;
			break;
		case 3:
			config = CHANNEL_SWAP_MIX;
			break;
		default:
			config = CHANNEL_SWAP_LR;
			break;
		}
		ioctl(fd, IOCMD_OUTPUT_SET_CHANNELSWAP, &config);
		close(fd);
}


INT32S KeyDownWhenInfoBarOnshowOrOnHide(PHWND hwnd, INT32S lpParam)
{

	INT32U *key_value = (INT32U *)lpParam ;
	int oldindex = CurrInfoBarIndex ;
	PHWND dir_hwnd = AWFindWinCtrlByName(MoviePlayState);
	PHWND paint_hwnd = AWFindWinCtrlByName(AviSubCtrl);
	PHWND dir_hwnd2 = AWFindWinCtrlByName(MoviePlayInfoBar);
	
	WaittingTime = 0;
		
	// CheckVdeioState
	switch(*key_value)	{
		case UOP_AUDIO:
/*
			if(audio_track_flag<4)
				audio_track_flag++;
			else
				audio_track_flag = 0;
				ChangeSoundTrack(audio_track_flag);
*/
			break;
			
		case UOP_RESUME:
			#ifdef TIME_SEARCH
			cur_time_search = time_search_none;
			#endif
			PlayBackResume = 1 ;
			break;
			
	 	case UOP_HOME:
			#ifdef TIME_SEARCH
			cur_time_search = time_search_none;
			#endif
			if(CheckMediaPlaybackApp())
				CloseMediaPlaybackApp(0xff);
			
		 	*key_value = UOP_NOP;
		 	PlayBackHome = 1 ;

				break;
	
		case UOP_OSD:
			if(AWIsVisibleWinControl(hwnd))// visible
			{
//				if(subpic_enable)
//				{
//					AWHideWinControl(hwnd);
//					if(paint_hwnd)
//						AWShowWinControl(paint_hwnd,0);
//				}
//				else
//				{
					AWHideWinControl(hwnd);
//				}

			}
//			else if(AWIsVisibleWinControl(paint_hwnd))
//			{
//				if(paint_hwnd)
//				{
//					AWSendMessage(paint_hwnd, WM_PAINT_DRAW_INFO, 0) ;
//					AWSendMessage(paint_hwnd,WM_PAINT_FINISH,0);
//					AWHideWinControl(paint_hwnd);
//				}
//				AWShowWinControl(hwnd,0);
//				AWSetFocus(hwnd);
//			}
			else
			{
				WaittingTime = 0 ;
				AWShowWinControl(hwnd,0);
				AWSetFocus(hwnd);
			}
			*key_value = UOP_NOP;

				break;

		case UOP_UP:
			if(!AWIsVisibleWinControl(dir_hwnd2)){  //when infobar is disvisible,the left key will move the direction
				return 0 ;
			}
			#ifdef WISTAR_VERSION
			*key_value = UOP_PREVIOUS_CHAP;
			#endif
                 #ifdef TIME_SEARCH
			if(cur_time_search!= time_search_none)
			{
				UpdateTime = 1;
				gPlayerUpdateSearchTime(1);
				gPlayerUpdateTimeInfo();
				UpdateTime = 0;
				
			}
			*key_value = UOP_NOP ;
			#endif
			*key_value = UOP_NOP ;
			break;

		case UOP_DOWN:
			if(!AWIsVisibleWinControl(dir_hwnd2)){  //when infobar is disvisible,the left key will move the direction
				return 0 ;
			}
			#ifdef WISTAR_VERSION
			*key_value = UOP_NEXT_CHAP;
			#endif
                 #ifdef TIME_SEARCH
			if(cur_time_search!= time_search_none)
			{
				UpdateTime = 1;
				gPlayerUpdateSearchTime(0);
				gPlayerUpdateTimeInfo();
				UpdateTime = 0;
			}
			*key_value = UOP_NOP ;
                        #endif
			*key_value = UOP_NOP ;
			break;
			
		case UOP_LEFT:
			if(!AWIsVisibleWinControl(dir_hwnd2)){  //when infobar is disvisible,the left key will move the direction
				return 0 ;
			}
			// 0 data_draw is background
			if(CurrInfoBarIndex != 1) CurrInfoBarIndex-- ;
			UpdateBarIconSelectState(oldindex, CurrInfoBarIndex);
			*key_value = UOP_NOP ;
		  		break;
			  
		case UOP_RIGHT:
			if(!AWIsVisibleWinControl(dir_hwnd2)){  //when infobar is disvisible,the left key will move the direction
				return 0 ;
			}
			// 9 draw_data is PlayTime
			#ifdef TIME_SEARCH
			if(TimeSearchFlag == 1)
			{
				if(CurrInfoBarIndex < 11) 
					CurrInfoBarIndex++ ;
			}
			else{
				if(CurrInfoBarIndex <8) 
					CurrInfoBarIndex++ ;
			}
			#else
			if(CurrInfoBarIndex < 8) CurrInfoBarIndex++ ;			
			#endif
			UpdateBarIconSelectState(oldindex, CurrInfoBarIndex);
			*key_value = UOP_NOP ;
				break;

		case UOP_PREVIOUS_CHAP:
			#ifdef TIME_SEARCH
			cur_time_search = time_search_none;
			#endif
			UpdateBarIconSelectState(oldindex, 1);
//			subpic_enable = 0;
			if((paint_hwnd)&&(AWIsVisibleWinControl(paint_hwnd)))
			{
					AWSendMessage(paint_hwnd, WM_PAINT_DRAW_INFO, 0) ;
					AWSendMessage(paint_hwnd,WM_PAINT_FINISH,0);
					AWHideWinControl(paint_hwnd);
			}
				break;						

		case UOP_FAST_BACKWARD:
			#ifdef TIME_SEARCH
			cur_time_search = time_search_none;
			#endif
		 	UpdateBarIconSelectState(oldindex, 2);
		 	
			if(PlayEffect == PLAY)
				hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
			else 
			if(PlayEffect == FBx4)
				hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
				
			if(AWIsVisibleWinControl(hwnd))
			{
				hwnd->pClass->ClassProc(hwnd,WM_PAINT_DRAW_INFO,3);
				hwnd->pClass->ClassProc(hwnd,WM_PAINT_FINISH,0);	
			}		 	
				break;

		case UOP_END_PAUSE:
			#ifdef TIME_SEARCH
			cur_time_search = time_search_none;
			#endif
			UpdateBarIconSelectState(oldindex, 3);  /* after this process there is a changed VideoState 
														to accounding to set 
														not only left or right Key down but */

			if(PlayEffect == PLAY)
			{
				*key_value = UOP_PAUSE ;
				hwnd->draw_info[3].draw_data = (INT32U)ICON_PAUSE_FOCUS_PLBK ;
				VideoState = PLAY ;
			}
			else 
			{
				hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_FOCUS_PLBK ;
				VideoState = PAUSE ;
			}

			if(AWIsVisibleWinControl(hwnd))
			{
				hwnd->pClass->ClassProc(hwnd,WM_PAINT_DRAW_INFO,3);
				hwnd->pClass->ClassProc(hwnd,WM_PAINT_FINISH,0);	
			}

				break;

		case UOP_FAST_FORWARD:
			#ifdef TIME_SEARCH
			cur_time_search = time_search_none;
			#endif
			UpdateBarIconSelectState(oldindex, 4);
			
			if(PlayEffect == PLAY)
				hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
			else 
			if(PlayEffect == FFx4)
				hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
				
			if(AWIsVisibleWinControl(hwnd))
			{
				hwnd->pClass->ClassProc(hwnd,WM_PAINT_DRAW_INFO,3);
				hwnd->pClass->ClassProc(hwnd,WM_PAINT_FINISH,0);	
			}
				break;

		case UOP_NEXT_CHAP:
			UpdateBarIconSelectState(oldindex, 5);
			#ifdef TIME_SEARCH
			cur_time_search = time_search_none;
			#endif
//			subpic_enable = 0;
			if((paint_hwnd)&&(AWIsVisibleWinControl(paint_hwnd)))
			{
					AWSendMessage(paint_hwnd, WM_PAINT_DRAW_INFO, 0) ;
					AWSendMessage(paint_hwnd,WM_PAINT_FINISH,0);
					AWHideWinControl(paint_hwnd);
			}
				break;
					
		case UOP_STOP:
			#ifdef TIME_SEARCH
			cur_time_search = time_search_none;
			#endif
			PlayBackResume = 1 ;
			UpdateBarIconSelectState(oldindex, 6);
				break;
																
		case UOP_ZOOM:
			UpdateBarIconSelectState(oldindex, 7);
				break;
			  
		case UOP_ENTER:
		 	*key_value = OnEnterExpress();
		 		break;

/////////////////////////////////////////////////////////////////////////////
		case UOP_VOL_MINUS:
		case UOP_VOL_PLUS:
/*			
			if((PlayState == FASTFOR)||(PlayState == FASTBACK)||(isMute == MUTE)){
				*key_value = UOP_NOP ;
				return 0 ;
			}
			else{
*/				
				if(!dir_hwnd)
					break;

				if(isMute == MUTE)
					isMute = UNMUTE ;
				
				if(GPIO_MUTE_STATUS)
					GPIO_MB_UNMUTE;
				
				PlayBack_unMute_ShowFlag = 1 ;	
				PlayBack_unMute_waitting = 0 ;
				
				dir_hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				dir_hwnd->draw_info[1].draw_data = (INT32U)ICON_UNMUTE ;
				dir_hwnd->draw_info[2].draw_data = (INT32U)vol_value[Volume_Value] ;
			
				dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 0);
				dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 1);
				dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 2);
				dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_FINISH, 0);

//			}
			break;
		
		case UOP_MUTE:
			if(!dir_hwnd)
				break;
				
			if(isMute == UNMUTE) 
			{
				dir_hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS120X32 ;
				dir_hwnd->draw_info[1].draw_data = (INT32U)0 ;
				dir_hwnd->draw_info[2].draw_data = (INT32U)0 ;
				dir_hwnd->draw_info[3].draw_data = (INT32U)0 ;
			}
			else 
			{
				dir_hwnd->draw_info[0].draw_data = (INT32U)ICON_INFOBAR_STATUS1 ;
				dir_hwnd->draw_info[1].draw_data = (INT32U)ICON_MUTE ;
				dir_hwnd->draw_info[2].draw_data = (INT32U)0 ;
				dir_hwnd->draw_info[3].draw_data = (INT32U)0 ;
			}
			
			dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 0);
			dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 1);
			dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 2);
			dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_FINISH, 0);

			break;

		default:
				break;	
	}
			
    return 0 ;

}

void ResumFromMoviePlayBack()
{

	if(NODIR_FLAG == 0)
	{
		GUIShowWindow(WinFileList);
	}
	else 
	{
		GUIShowWindow(WinLogo);
	}			
}


void RefurbishInfoBar(int num)
{
	PHWND dir_hwnd = AWFindWinCtrlByName(MoviePlayInfoBar);
	if(!dir_hwnd)
		return ;
		
	if(num != 11)	
		return ;
		
	if(CurrInfoBarIndex == 3)
		dir_hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_FOCUS_PLBK ;
	else
		dir_hwnd->draw_info[3].draw_data = (INT32U)ICON_PLAY_LOSE_PLBK ;
		
	if(AWIsVisibleWinControl(dir_hwnd))
	{
		dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_DRAW_INFO, 3);
		dir_hwnd->pClass->ClassProc(dir_hwnd, WM_PAINT_FINISH, 0);
	}
}

INT32S AviSubCtrlOnShow(PHWND hwnd, INT32S lpParam)
{
//    oldcolor=AWSetForeground(GRAY_COLOR);
    sub_txt_line1[0] = 0 ;
    sub_txt_line2[0] = 0 ;
    return 0 ;
}

INT32S AviSubCtrlOnHide(PHWND hwnd, INT32S lpParam)
{
//	AWSetForeground(oldcolor);
	hwnd->style |=WS_DISVISIBLE;
	return 0 ;
}

INT32S UpdateAviSub(void) 
{
	PHWND hwnd = AWFindWinCtrlByName(AviSubCtrl);
    if(hwnd == NULL)
        return 0 ;
    if(subpic_status == SUBPIC_OFF) {
        AviSetSubOn(0) ;
    }
//    if(subpic_enable)
//        AWShowWinControl(hwnd,0);

    return 0 ;
}

void Set_subpic_enable(flag)
{
subpic_enable = flag ;
}
